/*
 * @Author: szx
 * @Date: 2022-03-16 14:15:06
 * @LastEditTime: 2022-03-16 14:21:51
 * @Description:
 * @FilePath: \leetcode\1-99\21\21_2.js
 */
function ListNode(val, next) {
    this.val = val === undefined ? 0 : val;
    this.next = next === undefined ? null : next;
}

/**
 * @param {ListNode} list1
 * @param {ListNode} list2
 * @return {ListNode}
 */
var mergeTwoLists = function (list1, list2) {
    const prev = new ListNode(-1);
    let node = prev;
    while (list1 && list2) {
        if (list1.val > list2.val) {
            node.next = new ListNode(list2.val);
            list2 = list2.next;
        } else {
            node.next = new ListNode(list1.val);
            list1 = list1.next;
        }
        node = node.next;
    }
    node.next = list1 == null ? list2 : list1;
    return prev.next;
};
